<include file="Common:minheader" />
<!-- /. NAV SIDE  -->
<form class="layui-form" action="">
    <input type="hidden" name="type" value="3">
	<div class="layui-form-item">
		<label class="layui-form-label">名称</label>
		<div class="layui-input-block">
		  <input type="text" name="title" required  lay-verify="required" placeholder="请输入图片名称" autocomplete="off" class="layui-input">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">图片</label>
		<div class="layui-input-block">
			<div class="layui-upload">
			  <button type="button" class="layui-btn" id="test2">上传图片</button>
			  <div class="layui-upload-list" id="demo2" data-id="">
				<if condition="!empty($info['img_url'])">
					<div class="imgcss"><input type="hidden" name="img_url" id="smallimage1" value="{$info.img_url}"><a href="{$info.img_url}" target="_blank"><img src="{$info.img_url}" width="100"></a></div>
				</if>
			  </div>
			  <div id="demoText1"></div>
			  <div class="layui-form-mid layui-word-aux"></div>
			</div> 
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">是否启用</label>
		<div class="layui-input-block">
		  <input type="radio" name="status" value="1" title="是" checked>
		  <input type="radio" name="status" value="0" title="否">
		</div>
	</div>
	<div class="layui-form-item">
		<div class="layui-input-block">
		  <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
		  <button type="reset" class="layui-btn layui-btn-primary">重置</button>
		</div>
  </div>
</form>
<script>
	//Demo
	layui.use('form', function(){
	  var form = layui.form;
	  layui.use('upload', function(){
    		var $ = layui.jquery
    		,upload = layui.upload;
    		var uploadInst = upload.render({
    			elem: '#test2'
    			,url: "{:U('Common/uploadImage')}"
    			,size:'0'
    			,exts:'jpeg|gif|png|jpg'
    			,multiple: false
    			,method: 'POST'
    			,before: function(obj){
    				//预读本地文件示例，不支持ie8
    				obj.preview(function(index, file, result){
    					$('#demo2').html('<div class="imgcss"><input type="hidden" name="img_url" id="smallimage1"><img src="'+result+'" width="100"></div>'); //文件名
    				});
    			}
    			,done: function(res){
    				//如果上传失败
    				if(res.code==0){
    					return layer.msg(res.value);
    				}else{
    					$('#smallimage1').val(res.value);
    				}
    			}
    			,error: function(){
    				//演示失败状态，并实现重传
    				var demoText = $('#demoText1');
    				demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
    				demoText.find('.demo-reload').on('click', function(){
    					uploadInst.upload();
    				});
    			}
    		});
    	});
	  //监听提交
	  form.on('submit(formDemo)', function(data){
			var cont = data.field;
			$.ajax({
				url:"{:U('Configure/addSystemPic')}",
				type:'post',
				dataType:'json',
				data:cont,
				success:function(data){
					if(data.code==0){
						layer.alert(data.message);
					}else{
						layer.alert(data.message, function(index){
							//do something
							window.parent.location.reload();
							var index = parent.layer.getFrameIndex(window.name); 
							parent.layer.close(index);
						});
					}
				}
			});
			//layer.msg(JSON.stringify(data.field));
			return false;
	  });
	});
</script>
<!-- /. PAGE INNER  -->
<include file="Common:footer" />